package com.solace.disruptor.test;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;


public class StringShort {
    public static void main(String[] args) {
        String stringForShort = StringShort.getStringForShort((short) -19702);
        System.out.println(stringForShort);

    }
    public static String getStringForShort(Short number){
        ByteBuffer alloceate = ByteBuffer.allocate(2);
        alloceate.order(ByteOrder.BIG_ENDIAN);
        alloceate.putShort(number);
        alloceate.flip();
        byte[] array = alloceate.array();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("OX");
        for (int i=0;i<array.length;i++){
            int value = array[i] & 0XFF;
            String hexStr = Integer.toString(value, 16);
            hexStr=hexStr.length() <= 1 ? "0" + hexStr : hexStr;
            stringBuffer.append(hexStr);
        }
        return stringBuffer.toString().toUpperCase();
    }
}
